@extends('layout.admin')
@section('content')
    <style>
        .layui-btn {
            height: 25px;
            line-height: 25px;
        }

        table {
            width: 100% !important;
        }
    </style>
    <div style="">
        <div style="padding: 5px 15px 5px 15px;border:1px solid #e8e8e8;background: white;border: 1px solid #e6e6e6">
           <span class="layui-breadcrumb" style="visibility:visible">
              <a href="{{url('/')}}"><i class="layui-icon" style="font-size: 14px"></i> 首页  </a>
              <a href="{{url('/admin')}}"><cite> 文章管理 </cite></a>
            </span>
        </div>
        <div style="padding: 5px 15px 0 15px">
            <fieldset class="layui-elem-field layui-field-title">
                <legend>用户管理</legend>
            </fieldset>
            <div class="layui-tab layui-tab-card">
                <ul class="layui-tab-title">
                    <li class="layui-this"><a href="{{url('/admin')}}">用户列表</a></li>
                    <li><a href="{{url('/admin/create')}}">用户添加</a></li>
                </ul>
                <div class="layui-tab-content" style="height: 100%;">
                    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
                        <legend style="font-size: 16px;">查询条件</legend>
                    </fieldset>
                    <form action="" class="layui-form" style="background: white;padding: 15px 15px 10px;">
                        <div class="layui-form-item" style="margin-bottom: 0">
                            <div class="layui-input-block" style="margin-left: 0;width: 100px;float: left;margin-right: 10px;">
                                <select name="options" lay-filter="aihao">
                                    @if(isset($inputs['keywords']))
                                        @if($inputs['keywords'] == ''))
                                        <option value="name" selected="">昵称</option>
                                        <option value="mobile">手机</option>
                                        <option value="email">邮箱</option>
                                        @elseif ($inputs['options'] == 'name')
                                            <option value="name" selected="">昵称</option>
                                            <option value="mobile">手机</option>
                                            <option value="email">邮箱</option>
                                        @elseif ($inputs['options'] == 'mobile')
                                            <option value="name">昵称</option>
                                            <option value="mobile" selected="">手机</option>
                                            <option value="email">邮箱</option>
                                        @elseif ($inputs['options'] == 'email')
                                            <option value="name">昵称</option>
                                            <option value="mobile">手机</option>
                                            <option value="email" selected="">邮箱</option>
                                        @endif
                                    @else
                                        <option value="name" selected="">昵称</option>
                                        <option value="mobile">手机</option>
                                        <option value="email">邮箱</option>
                                    @endif
                                </select>
                            </div>
                            <div class="layui-inline" style="float: left;">
                                <div class="layui-input-inline">
                                    @if(isset($inputs['keywords']))
                                        @if($inputs['keywords'] == '' )
                                            <input type="text" name="keywords" placeholder="输入查询关键词" autocomplete="off" class="layui-input">
                                        @else
                                            <input type="text" name="keywords" placeholder="输入查询关键词" value="{{$inputs['keywords']}}" autocomplete="off" class="layui-input">
                                        @endif
                                    @else
                                        <input type="text" name="keywords" placeholder="输入查询关键词" autocomplete="off" class="layui-input">
                                    @endif
                                </div>
                            </div>
                            <div class="layui-input-block" style="float: left;margin-left: 0px;">
                                <button class="layui-btn" lay-submit="" lay-filter="demo1" style="height: 38px;">查询
                                </button>
                            </div>
                        </div>
                    </form>
                    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
                        <legend style="font-size: 16px;">数据列表 【共有{{$sun}}条数据】</legend>
                    </fieldset>
                    <div class="layui-form layui-border-box layui-table-view" lay-filter="LAY-table-1" style="background-color:#88888;">
                        <div class="layui-table-box">
                            @if(count($result) > 0)
                                <table cellspacing="0" cellpadding="0" border="0" class="layui-table">
                                    <thead>
                                    <tr>
                                        <th data-field="id" class="laytable-cell-1-id">
                                            <div class="layui-table-cell">ID</div>
                                        </th>
                                        <th data-field="title">
                                            <div class="layui-table-cell">头像</div>
                                        </th>
                                        <th data-field="cate">
                                            <div class="layui-table-cell">名称</div>
                                        </th>
                                        <th data-field="author">
                                            <div class="layui-table-cell">手机</div>
                                        </th>
                                        <th data-field="click">
                                            <div class="layui-table-cell">邮箱</div>
                                        </th>
                                        <th data-field="status">
                                            <div class="layui-table-cell">状态</div>
                                        </th>
                                        <th data-field="laytable-cell-1-0" class="layui-oper">
                                            <div class="layui-table-cell">操作</div>
                                        </th>
                                    </tr>
                                    </thead>
                                    <tbody lay-filter="tbodys">
                                    @foreach($result as $value)
                                        <tr data-index="0" class="layui-table-cell">
                                            <td data-field="id" class="laytable-cell-1-id">
                                                <div class="layui-table-cell">{{$value->id}}</div>
                                            </td>
                                            <td data-field="title">
                                                <div class="layui-table-cell">
                                                    <img src="{{env('WEBSITE_URL') .'/storage/' .$value->avatar}}" alt="" class="avatar">
                                                </div>
                                            </td>
                                            <td data-field="cate">
                                                <div class="layui-table-cell">{{$value->name}}</div>
                                            </td>
                                            <td data-field="author">
                                                <div class="layui-table-cell">{{$value->mobile}}</div>
                                            </td>
                                            <td data-field="click">
                                                <div class="layui-table-cell">{{$value->email}}</div>
                                            </td>
                                            <td data-field="status">
                                                <div class="layui-table-cell">
                                                    @if($value->status == 1)
                                                        <span class="layui-badge layui-bg-green">激活</span>
                                                    @else
                                                        <span class="layui-badge layui-bg-gray">锁定</span>
                                                    @endif
                                                </div>
                                            </td>
                                            <td data-field="laytable-cell-1-0">
                                                <div class="layui-table-cell">
                                                    <a class="layui-btn layui-btn-xs" lay-event="detail" href="admin/{{$value->id}}/edit">编辑</a>
                                                    <a class="layui-btn layui-btn-danger layui-btn-xs" onclick="del({{$value->id}})" href="javascipt:;">删除</a>
                                                </div>
                                            </td>
                                        </tr>
                                    @endforeach
                                    </tbody>
                                </table>
                            @else
                                <div class="Noquery">不好意思,还没有这样的数据哦</div>
                            @endif
                        </div>
                    </div>
                    {{ $result->links() }}
                </div>
            </div>
        </div>
    </div>
    <script>
        layui.use(['form', 'table', 'layer'], function () {
            var form = layui.form;
            var table = layui.table;
            var layer = layui.layer;
            var $ = layui.$
            //监听提交
            form.on('submit(formDemo)', function (data) {
                layer.msg(JSON.stringify(data.field));
                return false;
            });
        });

        function del(id) {
            layer.confirm('确认删除么?', {btn: ['确认', '取消']}, function () {
                layui.$.post("{{url('admin/')}}/" + id, {_method: "DELETE",_token: "{{csrf_token()}}",
                }, function (data) {
                    if (data.success){
                        layer.msg(data.msg_message,{icon:6});
                        setTimeout('location.href = location.href', 1000);
                    }else{
                        layer.msg(data.msg_message, {icon: 5});
                    }
                });
            },function () {
            })
        }
    </script>
    <style>
        .laytable-cell-1-id {
            text-align: center;
            width: 6%;
        }

        .layui-oper {
            width: 10%;
        }

        .avatar {
            width: 50px;
            height: 50px;
            border-radius: 50%;
        }

        .layui-table-cell {
            text-align: center;
            line-height: 50px;
            height: 50px;
        }

        .Noquery {
            text-align: center;
            font-size: 18px;
            padding: 10px;
            color: #666666;
        }
    </style>

@endsection